package cn.itsource.system.service.impl;

import cn.itsource.basic.utils.PageResult;
import cn.itsource.system.domain.SystemDictionaryType;
import cn.itsource.system.mapper.SystemDictionaryDetailMapper;
import cn.itsource.system.mapper.SystemDictionaryTypeMapper;
import cn.itsource.system.query.SystemDictionaryTypeQuery;
import cn.itsource.system.service.SystemDictionaryTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
public class SystemDictionaryTypeServiceImpl implements SystemDictionaryTypeService {

    @Autowired
    private SystemDictionaryTypeMapper systemDictionaryTypeMapper;

    @Autowired
    private SystemDictionaryDetailMapper systemDictionaryDetailMapper;

    @Override
    public List<SystemDictionaryType> findAll() {
        return systemDictionaryTypeMapper.findAll();
    }

    @Override
    public SystemDictionaryType findOne(Long id) {
        return systemDictionaryTypeMapper.findOne(id);
    }

    @Override
    public void add(SystemDictionaryType systemDictionaryType) {

        systemDictionaryTypeMapper.add(systemDictionaryType);
    }

    @Override
    public void update(SystemDictionaryType systemDictionaryType) {
        systemDictionaryTypeMapper.update(systemDictionaryType);
    }

    @Override
    public void delete(Long id) {
        // 根据types_id删除t_systemdictionarydetail数据
        systemDictionaryDetailMapper.patchDelType(id);
        systemDictionaryTypeMapper.delete(id);
    }

    @Override
    public void patchdel(Long[] ids) {
        // 根据types_id删除t_systemdictionarydetail数据
        for (Long id : ids) {
            systemDictionaryDetailMapper.patchDelType(id);
        }
        systemDictionaryTypeMapper.patchdel(ids);
    }

    @Override
    public PageResult<SystemDictionaryType> queryPage(SystemDictionaryTypeQuery SystemDictionaryTypeQuery) {
        Integer totals = systemDictionaryTypeMapper.queryCount(SystemDictionaryTypeQuery);
        List<SystemDictionaryType> list = systemDictionaryTypeMapper.queryData(SystemDictionaryTypeQuery);
        return new PageResult<SystemDictionaryType>(totals,list);
    }
}
